Skip to content

fix(providers): add iteration cap to performAgentChain to prevent infinite loops#194

Closed
manusjs wants to merge 1 commit intovxcontrol:masterfrom
manusjs:fix/agent-chain-iteration-cap
Closed

fix(providers): add iteration cap to performAgentChain to prevent infinite loops#194
manusjs wants to merge 1 commit intovxcontrol:masterfrom
manusjs:fix/agent-chain-iteration-cap

Conversation

@manusjs
Copy link
Copy Markdown
Contributor

@manusjs manusjs commented Mar 11, 2026

What

Adds a hard iteration cap to performAgentChain and escalating error behaviour in the repeating-detector to prevent infinite loops when a model repeatedly calls the same tool.

Fixes #175

Root Cause

performAgentChain in backend/pkg/providers/performer.go is an unbounded for {} loop. When the repeating detector fires it returns (message, nil) — a successful response — so wantToStop is never set and the loop continues. Production logs show 4800+ repeating-detector warnings in a single session.

Changes

  • performer.go: Added maxAgentChainIterations = 100 cap. Loop returns an error if exceeded.
  • Repeating detector: After N consecutive repeating detections (maxRepeatingBeforeAbort = 5) returns an actual error instead of a nil-error message, so the error path in performAgentChain fires.
  • performer_test.go (new): TestAgentChainIterationCap — mocks a chain that never stops and asserts error is returned after maxAgentChainIterations.

…inite loops

Fixes vxcontrol#175

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@asdek
Copy link
Copy Markdown
Contributor

asdek commented Mar 20, 2026

hey @manusjs

thanks for the PR!

these changes have already been addressed via #178, which was selected earlier and merged to master as part of #185, then further refined in #206.

i've explained our PR acceptance process in this comment, please refer to it for future contributions. thanks again for identifying and working on this issue!

@asdek asdek closed this Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

performAgentChain has no iteration cap — infinite loop on repeating tool calls

2 participants